﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_quipment_maintenance
	/// </summary>
	public partial class oa_quipment_maintenance
	{
		public oa_quipment_maintenance()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("ID", "oa_quipment_maintenance"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_quipment_maintenance");
			strSql.Append(" where ID=@ID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32,11)};
			parameters[0].Value = ID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_quipment_maintenance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_quipment_maintenance(");
			strSql.Append("ID,RepairDate,RepairPeople,FaultCode,FaultInfo,ReceiverPeople,IsSMS,HandlePeople,HandleResult,ResultDate,ResultInfo,CreatePeopleCode,CreateDate)");
			strSql.Append(" values (");
			strSql.Append("@ID,@RepairDate,@RepairPeople,@FaultCode,@FaultInfo,@ReceiverPeople,@IsSMS,@HandlePeople,@HandleResult,@ResultDate,@ResultInfo,@CreatePeopleCode,@CreateDate)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32,11),
					new MySqlParameter("@RepairDate", MySqlDbType.DateTime),
					new MySqlParameter("@RepairPeople", MySqlDbType.VarChar,20),
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5),
					new MySqlParameter("@FaultInfo", MySqlDbType.VarChar,400),
					new MySqlParameter("@ReceiverPeople", MySqlDbType.VarChar,10),
					new MySqlParameter("@IsSMS", MySqlDbType.Int32,11),
					new MySqlParameter("@HandlePeople", MySqlDbType.VarChar,10),
					new MySqlParameter("@HandleResult", MySqlDbType.Int32,11),
					new MySqlParameter("@ResultDate", MySqlDbType.DateTime),
					new MySqlParameter("@ResultInfo", MySqlDbType.VarChar,400),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,10),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.RepairDate;
			parameters[2].Value = model.RepairPeople;
			parameters[3].Value = model.FaultCode;
			parameters[4].Value = model.FaultInfo;
			parameters[5].Value = model.ReceiverPeople;
			parameters[6].Value = model.IsSMS;
			parameters[7].Value = model.HandlePeople;
			parameters[8].Value = model.HandleResult;
			parameters[9].Value = model.ResultDate;
			parameters[10].Value = model.ResultInfo;
			parameters[11].Value = model.CreatePeopleCode;
			parameters[12].Value = model.CreateDate;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_quipment_maintenance model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_quipment_maintenance set ");
			strSql.Append("RepairDate=@RepairDate,");
			strSql.Append("RepairPeople=@RepairPeople,");
			strSql.Append("FaultCode=@FaultCode,");
			strSql.Append("FaultInfo=@FaultInfo,");
			strSql.Append("ReceiverPeople=@ReceiverPeople,");
			strSql.Append("IsSMS=@IsSMS,");
			strSql.Append("HandlePeople=@HandlePeople,");
			strSql.Append("HandleResult=@HandleResult,");
			strSql.Append("ResultDate=@ResultDate,");
			strSql.Append("ResultInfo=@ResultInfo,");
			strSql.Append("CreatePeopleCode=@CreatePeopleCode,");
			strSql.Append("CreateDate=@CreateDate");
			strSql.Append(" where ID=@ID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@RepairDate", MySqlDbType.DateTime),
					new MySqlParameter("@RepairPeople", MySqlDbType.VarChar,20),
					new MySqlParameter("@FaultCode", MySqlDbType.VarChar,5),
					new MySqlParameter("@FaultInfo", MySqlDbType.VarChar,400),
					new MySqlParameter("@ReceiverPeople", MySqlDbType.VarChar,10),
					new MySqlParameter("@IsSMS", MySqlDbType.Int32,11),
					new MySqlParameter("@HandlePeople", MySqlDbType.VarChar,10),
					new MySqlParameter("@HandleResult", MySqlDbType.Int32,11),
					new MySqlParameter("@ResultDate", MySqlDbType.DateTime),
					new MySqlParameter("@ResultInfo", MySqlDbType.VarChar,400),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,10),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@ID", MySqlDbType.Int32,11)};
			parameters[0].Value = model.RepairDate;
			parameters[1].Value = model.RepairPeople;
			parameters[2].Value = model.FaultCode;
			parameters[3].Value = model.FaultInfo;
			parameters[4].Value = model.ReceiverPeople;
			parameters[5].Value = model.IsSMS;
			parameters[6].Value = model.HandlePeople;
			parameters[7].Value = model.HandleResult;
			parameters[8].Value = model.ResultDate;
			parameters[9].Value = model.ResultInfo;
			parameters[10].Value = model.CreatePeopleCode;
			parameters[11].Value = model.CreateDate;
			parameters[12].Value = model.ID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_quipment_maintenance ");
			strSql.Append(" where ID=@ID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32,11)};
			parameters[0].Value = ID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_quipment_maintenance ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_quipment_maintenance GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,RepairDate,RepairPeople,FaultCode,FaultInfo,ReceiverPeople,IsSMS,HandlePeople,HandleResult,ResultDate,ResultInfo,CreatePeopleCode,CreateDate from oa_quipment_maintenance ");
			strSql.Append(" where ID=@ID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32,11)};
			parameters[0].Value = ID;

			becom.Model.oa_quipment_maintenance model=new becom.Model.oa_quipment_maintenance();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RepairDate"]!=null && ds.Tables[0].Rows[0]["RepairDate"].ToString()!="")
				{
					model.RepairDate=DateTime.Parse(ds.Tables[0].Rows[0]["RepairDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RepairPeople"]!=null && ds.Tables[0].Rows[0]["RepairPeople"].ToString()!="")
				{
					model.RepairPeople=ds.Tables[0].Rows[0]["RepairPeople"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FaultCode"]!=null && ds.Tables[0].Rows[0]["FaultCode"].ToString()!="")
				{
					model.FaultCode=ds.Tables[0].Rows[0]["FaultCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["FaultInfo"]!=null && ds.Tables[0].Rows[0]["FaultInfo"].ToString()!="")
				{
					model.FaultInfo=ds.Tables[0].Rows[0]["FaultInfo"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ReceiverPeople"]!=null && ds.Tables[0].Rows[0]["ReceiverPeople"].ToString()!="")
				{
					model.ReceiverPeople=ds.Tables[0].Rows[0]["ReceiverPeople"].ToString();
				}
				if(ds.Tables[0].Rows[0]["IsSMS"]!=null && ds.Tables[0].Rows[0]["IsSMS"].ToString()!="")
				{
					model.IsSMS=int.Parse(ds.Tables[0].Rows[0]["IsSMS"].ToString());
				}
				if(ds.Tables[0].Rows[0]["HandlePeople"]!=null && ds.Tables[0].Rows[0]["HandlePeople"].ToString()!="")
				{
					model.HandlePeople=ds.Tables[0].Rows[0]["HandlePeople"].ToString();
				}
				if(ds.Tables[0].Rows[0]["HandleResult"]!=null && ds.Tables[0].Rows[0]["HandleResult"].ToString()!="")
				{
					model.HandleResult=int.Parse(ds.Tables[0].Rows[0]["HandleResult"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ResultDate"]!=null && ds.Tables[0].Rows[0]["ResultDate"].ToString()!="")
				{
					model.ResultDate=DateTime.Parse(ds.Tables[0].Rows[0]["ResultDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ResultInfo"]!=null && ds.Tables[0].Rows[0]["ResultInfo"].ToString()!="")
				{
					model.ResultInfo=ds.Tables[0].Rows[0]["ResultInfo"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreatePeopleCode"]!=null && ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString()!="")
				{
					model.CreatePeopleCode=ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreateDate"]!=null && ds.Tables[0].Rows[0]["CreateDate"].ToString()!="")
				{
					model.CreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,RepairDate,RepairPeople,FaultCode,FaultInfo,ReceiverPeople,IsSMS,HandlePeople,HandleResult,ResultDate,ResultInfo,CreatePeopleCode,CreateDate ");
			strSql.Append(" FROM oa_quipment_maintenance ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_quipment_maintenance";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

